﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;

namespace l1cs.server.serverpackets
{
    public class S_RetrieveElfList : ServerBasePacket
    {
        public S_RetrieveElfList( int objid, L1PcInstance pc )
        {
            if ( pc.getInventory().getSize() < 180 )
            {
                int size = pc.getDwarfForElfInventory().getSize();
                if ( size > 0 )
                {
                    writeC( Opcodes.S_OPCODE_SHOWRETRIEVELIST );
                    writeD( objid );
                    writeH( size );
                    writeC( 9 ); // エルフ倉庫
                    foreach ( Object itemObject in pc.getDwarfForElfInventory().getItems() )
                    {
                        L1ItemInstance item = (L1ItemInstance)itemObject;
                        writeD( item.getId() );
                        writeC( 0 );
                        writeH( item.get_gfxid() );
                        writeC( item.getBless() );
                        writeD( item.getCount() );
                        writeC( item.isIdentified() ? 1 : 0 );
                        writeS( item.getViewName() );
                    }
                }
            }
            else
            {
                pc.sendPackets( new S_ServerMessage( 263 ) ); // \f1一人のキャラクターが持って歩けるアイテムは最大180個までです。
            }
        }

        override
        public byte[] getContent()
        {
            return getBytes();
        }

        override public String getType()
        {
            return "[S] S_RetrieveElfList";
        }
    }
}
